<?php
class Controller_Admin_Notice extends FLEA_Controller_Action {
	private $_ModelNotice;
	function Controller_Admin_Notice(){
		$this->_ModelNotice = & FLEA::getSingleton('Model_Notice');
	}
	
	function actionPost(){
		$page = isset ( $_GET ['page'] ) ? ( int ) $_GET ['page'] : 0;
		$pageSize = 20;
		
		$conditions = "type = 1";
		$order = " time desc ";
		
		FLEA::loadHelper ( 'pager' );
		$pager =  new FLEA_Helper_Pager ( $this->_ModelNotice, $page, $pageSize, $conditions, $order);
		$arranges = $pager->findAll ();
		
		$viewData = array(
			'list' => $arranges,
			'Title' => '公告管理', 
		 	'pagerData' => $pager->getPagerData(),
			'page' => $page,
		);
		$this->_executeView('Admin_Post_List.html',$viewData);
	}
	
	function actionPostAdd(){
		$viewData = array(
			'Title' => '添加公告', 
		);
		$this->_executeView('Admin_Post_Add.html',$viewData);
	}
	
	function actionPostDel(){
		$page = isset ( $_POST ['page'] ) ? ( int ) $_POST ['page'] : 0;
		$ids = $_POST ['ids'];

		if(!empty($ids)){
			foreach ($ids as $id){
				$conditions = 'notice_id = ' . $id;
				$this->_ModelNotice -> removeByConditions($conditions);
			}
		}
		js_alert("删除成功",'',$this->_url("Post",array('page'=>$page)));
	}
	
	function actionPostModify(){
		$nid = addslashes($_GET['nid']);
		$conditions = 'notice_id = ' . $nid;

		$list = $this->_ModelNotice->find($conditions);
		
		$viewData = array(
			'Title' => '编辑公告', 
			'list' => $list,
		);
		$this->_executeView('Admin_Post_Modify.html',$viewData);
	}
	
	function actionPostChange(){
		foreach($_POST as $key => $value){
			$$key = addslashes(trim($value));
		}
		$list = array(
			'title' => $title,
			'content' => $content,
			'time' => date('Y-m-d H:i:s'),
			'type' => $type,
		);
		if($notice_id){
			$list['notice_id'] = $notice_id;
		}
		$this->_ModelNotice -> save($list);
		js_alert("提交成功",'',url('Admin_Notice', 'Post'));	
	}
	
	function actionNews(){
		$page = isset ( $_GET ['page'] ) ? ( int ) $_GET ['page'] : 0;
		$pageSize = 20;
		
		$conditions = "type = 2";
		$order = " time desc ";
		
		FLEA::loadHelper ( 'pager' );
		$pager =  new FLEA_Helper_Pager ( $this->_ModelNotice, $page, $pageSize, $conditions, $order);
		$arranges = $pager->findAll ();
		
		$viewData = array(
			'list' => $arranges,
			'Title' => '最新动态管理', 
		 	'pagerData' =>$pager->getPagerData(),
			'page' => $page,
		);
		$this->_executeView('Admin_News_List.html',$viewData);
		
	}
	
	function actionNewsAdd(){
		$viewData = array(
			'Title' => '添加最新动态', 
		);
		$this->_executeView('Admin_News_Add.html',$viewData);		
	}
	
	function actionNewsDel(){
		$page = isset ( $_POST ['page'] ) ? ( int ) $_POST ['page'] : 0;
		$ids = $_POST ['ids'];

		if(!empty($ids)){
			foreach ($ids as $id){
				$conditions = 'notice_id = ' . $id;
				$this->_ModelNotice -> removeByConditions($conditions);
			}
		}
		js_alert("删除成功",'',$this->_url("News",array('page'=>$page)));		
	}
	
	function actionNewsModify(){
		$nid = addslashes($_GET['nid']);
		$conditions = 'notice_id = ' . $nid;

		$list = $this->_ModelNotice->find($conditions);
		
		$viewData = array(
			'Title' => '编辑最新动态', 
			'list' => $list,
		);
		$this->_executeView('Admin_News_Modify.html',$viewData);		
	}
	
	function actionNewsChange(){
		foreach($_POST as $key => $value){
			$$key = addslashes(trim($value));
		}
		$list = array(
			'title' => $title,
			'content' => $content,
			'time' => date('Y-m-d H:i:s'),
			'type' => $type,
		);
		if($notice_id){
			$list['notice_id'] = $notice_id;
		}
		$this->_ModelNotice -> save($list);
		js_alert("提交成功",'',url('Admin_Notice', 'News'));			
	}
}
?>